package com.src;

import java.util.Timer;
import java.util.TimerTask;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

/**
 * 
 * @author Administrator 自动Checked(通过消息队列)
 * 
 */
public class PictureWithRadioButton extends Activity {

	private final static int NEXT = 0;
	private ImageView imageView = null;
	private TextView textView = null;
	private RadioGroup radioGroup = null;
	private int[] images = new int[] { R.drawable.inner, R.drawable.b,
			R.drawable.c, R.drawable.d, R.drawable.e, R.drawable.f };

	private int currentImage = 0;
	private int currentRadio = 0;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		textView = (TextView) findViewById(R.id.textView);
		imageView = (ImageView) findViewById(R.id.imageView);
		radioGroup = (RadioGroup) findViewById(R.id.radioGroup);
		final Handler handler = new Handler() {

			@Override
			public void handleMessage(Message msg) {
				if (msg.what == NEXT) {
					imageView.setImageResource(images[currentImage++]);
					RadioButton button = (RadioButton) radioGroup
							.getChildAt(currentRadio++);
					button.setChecked(true);
					if (currentImage >= 6) {
						currentImage = 0;
						currentRadio = 0;
					}

				}

			}
		};
		new Timer().schedule(new TimerTask() {

			@Override
			public void run() {
				
				// handler.sendMessage(NEXT);
				Message msg = new Message();
				msg.what = NEXT;
				handler.sendEmptyMessage(NEXT);
			}
		}, 0, 1000);
	}
}
